import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		currentCity: {},
		bannerUrl: '',
		userInfo: {},
		talkAvatar: '',
		serveSelection: '',
		hospitalSelection: '',
		patientSelection: '',
		locationInfo: '',
		deparmentInfo: '',
		wechatInfo: '',
	},
	mutations: {
		setWechat(state, val) {
			console.log(val)
			state.wechatInfo = val
			uni.setStorageSync('wechatInfo_v1', val)
		},
		SET_CURRENTCITY: (state, city) => {
			state.currentCity = city
		},
		SET_BANNERURL: (state, bannerUrl) => {
			state.bannerUrl = bannerUrl
		},
		SET_USERINFO: (state, userInfo) => {
			state.userInfo = userInfo
			uni.setStorageSync('userInfo', userInfo)
		},
		SET_AVATAR: (state, avatar) => {
			state.talkAvatar = avatar
		},
		SET_ORDERS: (state, order) => {
			state.serveSelection = order
		},
		SET_HOSPITAL: (state, ctx) => {
			state.hospitalSelection = ctx
		},
		SET_PATIENT: (state, ctx) => {
			state.patientSelection = ctx
		},
		SET_LOCATION: (state, ctx) => {
			state.locationInfo = ctx
		},
		SET_DEPARTMENT: (state, ctx) => {
			state.deparmentInfo = ctx
		},
		SET_ORDER_DETAIL: (state, ctx) => {
			state.orderDetaile = ctx
		},
		CLEAR_STATE: (state, ctx) => {
			state = ctx
		}
	},
	actions: {},
	getters: {
		wechatInfo: state => {
			if (state.wechatInfo) {
				return state.wechatInfo
			}
			if (uni.getStorageSync('wechatInfo_v1')) {
				return uni.getStorageSync('wechatInfo_v1')
			}
			return ''
		},
		currentCity: state => state.currentCity,
		bannerUrl: state => state.bannerUrl,
		patientSelection: state => state.patientSelection,
		userInfo: state => {
			if (state.userInfo) {
				return state.userInfo
			}
			if (uni.getStorageSync('userInfo')) {
				return uni.getStorageSync('userInfo')
			}
			return null
		},
		talkAvatar: state => state.talkAvatar
	},
})
export default store